package com.wave.spring.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created by weibo.xwb on 2017/8/14.
 */
@Service
public class MyService implements EnvironmentAware {

    @Value("${spring.datasource.url}")
    private String url;
    @Override
    public void setEnvironment(Environment environment) {
        System.err.println("environment="+environment.getClass());
        ConfigurableEnvironment configurableEnvironment=(ConfigurableEnvironment)environment;
//        System.err.println("getSystemEnvironment"+configurableEnvironment.getSystemEnvironment());
//        System.err.println("getSystemProperties"+configurableEnvironment.getSystemProperties());
 //       System.err.println("resolvePlaceholders="+configurableEnvironment.resolvePlaceholders("abc is ${abc}"));
 //       System.err.println("abc="+configurableEnvironment.getProperty("abc"));

    }


    public String getUrl(){
        return url;
    }

    @PostConstruct
    public void init(){
        System.err.println("MyService url is "+url);
    }

    @PreDestroy
    public  void destory(){
        System.err.println("MyService is destory");
    }


    @Async
    public void syncDo(String s){
        System.out.println(s);
    }

    public  void doit(String s){
      //((MyService) AopContext.currentProxy()).doit(s);
        doit(s);
    }


}
